package com.jeeplus.modules.anny.utils;

import com.jeeplus.common.utils.IdGen;
import com.jeeplus.modules.anny.fileuse.entity.Attachment;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 文件上传工具类
 */
public class AttachUtils {
    /**
     *附件上传路径字典编码
     */
    public static final String DICT_FILE_UPLOAD_PATH = "arb_file_upload_path";

    /**
     *
     * @param list
     * @param UserOrProductId 商品或者用户的id
     * @param billType 商品类型
     * @return
     */
    public static List<Attachment> getAttachments(List<Map<String,Object>> list, String UserOrProductId,  String billType ){
        List<Attachment> attachList = new ArrayList<>();
        for (int i = 0; i <list.size() ; i++) {
            Attachment attachment = new Attachment();
            attachment.setRealName((String)list.get(i).get("realName"));
            attachment.setAscriptionId(UserOrProductId);
            attachment.setStoragepath((String) list.get(i).get("realPath"));
            attachment.setFileType(billType);
            attachment.preInsert();
            attachment.setDelFlag("0");
            attachList.add(attachment);
        }
        return attachList;
    }

    public static Attachment getAttachmet(Map<String,Object> map, String UserOrProductId, String billType){
        Attachment attachment = new Attachment();
        attachment.setFileName((String) map.get("fileName"));
        attachment.setFileType(billType);
        attachment.setRealName((String)map.get("realName"));
        attachment.setStoragepath((String)map.get("realPath"));
        attachment.setIsNewRecord(true);
        attachment.preInsert();
        attachment.setId(IdGen.uuid());
        attachment.setDelFlag("0");
        return attachment;
    }
}
